﻿<%@ Page Title="" Language="C#" MasterPageFile="~/EditWidows/eYUITreeList.Master"
    AutoEventWireup="true" CodeBehind="~/EditWidows/OrganizationalManager/PropCompany.aspx.cs"
    Inherits="ZX.WebApp.EditWidows.OrganizationalManager.PropCompany" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>
    <asp:Content ID="Content4" ContentPlaceHolderID="headerPlace" runat="server">
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <!--begin custom header content for this example-->
    <style type="text/css">
    .yui-skin-sam table {
	    width: 100%;
    }
    .firstTd
    {
        background-color:#DFE3E6;
        width:20%;
    }
    
    #tree {background: #fff; padding:1em;}
    #button-example-form fieldset, 
    #button-example-form fieldset div {
        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;

    }
    .yui-button#pushbutton2 button,
    .yui-button#pushbutton5 button, 
    .yui-button#pushbutton4 button,
    .yui-button .Add button {
        background: url(../button/assets/add.gif) center center no-repeat;
        text-indent: -4em;
        overflow: hidden;
        padding: 0 .75em;
        width: 2em;
        *margin-left: 4em;   /* IE only */
        *padding: 0 1.75em;  /* IE only */
    }  
    .yui-button#pushbutton3 button,
    .yui-button#pushbutton6 button, 
    .yui-button#pushbutton9 button {
        padding-left: 2em;
        background: url(../button/assets/add.gif) 10% 50% no-repeat; 
    }
        body
        {
            font:13px/1.231 arial,helvetica,clean,sans-serif;
            *font-size:small;
            *font:x-small; background: #eeeeee;
            text-align:center;
        }    
        a:link,a:visited{
            color:#1f376d;
        }
        a:hover{   color:#ff0000;
            text-decoration:underline;
        }  
        #fieldRight
        {
            height:99.5%;
        }
        
        .icon-doc { display:block; height: 22px; padding-left: 20px; background: transparent url(../../Images/icon/checked.gif) 0 -144px no-repeat; }

</style>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Appjs/Jquery.form.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="HeaderControl" runat="server">
    <!--  用于加载自定义脚本 -->
    <script src="../../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript"
        language="javascript"></script>
    <div id="divMessage" style="float: left">
        <font color="red">请先选择组织机构</font>
    </div>
    <div id="divButtons" style="display: none">
        <button type="button" id="btnCreateCompany" name="btnCreateCompany">
            新建公司</button>
        <button type="button" id="btnCreateSubCompany" name="btnCreateSubCompany">
            新建子公司</button>
        <button type="button" id="btnCreateDepartment" name="btnCreateDepartment">
            新建部门</button>
        <button type="button" id="btnCreateSubDepartment" name="btnCreateSubDepartment">
            新建子部门</button>
        <button type="button" id="btnEditDepartment" name="btnEditDepartment">
            修改</button>
        <button type="button" id="btnMove" name="btnMove">
            移动</button>
        <button type="button" id="btnDelete" name="btnDelete">
            删除</button>
        <button type="button" id="btnFull" name="btnFull">
            全屏</button>
        <button type="button" id="btnReload" name="btnReload">
            刷新</button>
        <button type="button" id="btnClose" name="btnClose">
            关闭当前页</button></div>
    <script type="text/javascript">
    YAHOO.example.init = function () {
         function onButtonClick(p_oEvent) {
                 switch(this.get("id"))
                 {       
//                    case "btnDelete": 
//                         break;
                     <% =InitBtnEvents %>

                    case "btnEditDepartment": 
                         fnEditDepartment();
                         break;
                    case "btnMove":
                         fnMove();
                         break;
                    case "btnFull": 
                         fnFull();
                         break;
                    case "btnClose":
                         fnAddMasterDetail();
                         break;
                    case "btnReload":
                         fnReload();
                         break;
                    case "btnAreaUserSet":
                        fnAreaUserSet();
                        break;
                    default:
                         break;
                 }                        
        }
        //删除部门
        //var btnDeleteDepartment = new YAHOO.widget.Button("btnDeleteDepartment");
        //btnDeleteDepartment.on("click", onButtonClick);
        //部门维护
       var btnEditDepartment = new YAHOO.widget.Button("btnEditDepartment");
        btnEditDepartment.on("click", onButtonClick);

        var btnMove = new YAHOO.widget.Button("btnMove");
        btnMove.on("click", onButtonClick);
//        var btnDelete = new YAHOO.widget.Button("btnDelete");
//        btnDelete.on("click", onButtonClick);
        YAHOO.util.Event.onContentReady("toolbar", function () {
        <% =BtnEvents  %>
        var btnFull = new YAHOO.widget.Button("btnFull");
        btnFull.on("click", onButtonClick);
        var btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
        var btnReload = new YAHOO.widget.Button("btnReload");
        btnReload.on("click", onButtonClick);
        });      
    } ();
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="leftPlaceHoder" runat="server">
    搜索:<input type="text" id="txtdeptName" onkeyup="serachDept();" style="width: 100px" />
    <button id="btnexpend">
        展开</button>
    <cc1:DeptTree ID="treeDiv1" runat="server"></cc1:DeptTree>
    <script type="text/javascript">
        var serachDept = function () {
            tree1._nodes[1].expandAll();
            $("#btnexpend").html("折叠");
            var key = $("#txtdeptName").val();
            $("a").css("color", "")
            $("a:contains('" + key + "')").css("color", "red");
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="DataPlaceHolder" runat="server">
    <table id="CompanyTable" border="1px" cellpadding="0px" cellspacing="0px" bgcolor="aliceblue">
        <caption>
            <img src="../../Images/icon/Depttype.gif" /><label id="lblTitle">集团</label></caption>
        <tr>
            <td class="firstTd">
                名称:
            </td>
            <td>
                <label id="LabelDeptName" name="DeptName">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                负责人职位(姓名):
            </td>
            <td>
                <label id="LabelPrincipal" name="iSun_ManagerName">
                    &nbsp
                </label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                创建时间:
            </td>
            <td>
                <label id="LblCreateTime" name="AddTime">
                    &nbsp
                </label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                <label id="lbldeptName">
                </label>
                助记码:
            </td>
            <td>
                <label id="LabelHelpCode" name="HelpCode">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                组织架构码:
            </td>
            <td>
                <label id="LabelCompanyPath" name="DeptPath">
                    &nbsp</label>
            </td>
        </tr>
        <tr id="trIncorporator">
            <td class="firstTd">
                法人代表:
            </td>
            <td>
                <label id="LabelIncorporator" name="ArtificialPerson">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                邮政编码:
            </td>
            <td>
                <label id="LabelPostCode" name="PostCode">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                联系电话:
            </td>
            <td>
                <label id="LabelPhone" name="Phone">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                传真:
            </td>
            <td>
                <label id="LabelFax" name="Fax">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                Email:
            </td>
            <td>
                <label id="LabelEmail" name="Email">
                    &nbsp</label>
            </td>
        </tr>
        <tr>
            <td class="firstTd">
                备注:
            </td>
            <td>
                <label id="LabelRemark" name="Description">
                    &nbsp</label>
            </td>
        </tr>
        <%--<tr><td  colspan="2" ><a href="">查看部门历史变更记录</a>:</td></tr>--%>
    </table>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ScriptPlaceHolder" runat="server">
    <!-- 通用方法 -->
    <script src="../../Scripts/common.js" type="text/javascript"></script>
    <script type="text/javascript">
    var PageTotal;
    var pageindex = 1;
    var pagesize = 25;

    var const_entityName="<%=EntityName%>",
        deptType=0,
        fkey="00000000-0000-0000-0000-000000000000",
        const_functionId   ="<% =FunctionID %>",//自定义条件
        const_Order ="<% =Order %>",           //排序  
        const_UserId = "<% = UserId %>",       //
        const_DataFields = [<% =DataFields %>],
        const_DataColums = [<% =DataColums %>],
        const_CustomCondition = encodeURI("<% =DefineCondition %>"),//查询方案条件
        const_PageTitle=encodeURI("<% =PageTitle %>"),
        initialRequestUrl="entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r="+Math.random()+"&condition="+window.decodeURI("<%=ForeignKey%>='"+fkey+"'");
     const_entityID = "<% =EntityId %>";  //实体ID名称
     (function() {
        var Dom = YAHOO.util.Dom,
            Event = YAHOO.util.Event;
 
        Event.onDOMReady(function() {
            var layout = new YAHOO.widget.Layout({
                minWidth: 1000,
                minHeight: 500,
                units: [
                    { position: 'left', width: 200, resize: true,header: '组织架构', body: 'left',collapse: true, gutter: '2px 0px', collapseSize: 50, scroll: true, maxWidth: 300 },
                    { position: 'center', minWidth: 400, minHeight: 200 }
                ]
            });
            layout.on('render', function() {
                var el = layout.getUnitByPosition('center').get('wrap');
                var layout2 = new YAHOO.widget.Layout(el, {
                    parent: layout,
                    minWidth: 400,
                    minHeight: 200,
                    units: [
                        { position: 'top', body: 'toolbar', height: 35, gutter: '1px', maxHeight: 80 },
                        { position: 'center', body: 'data', gutter: '1px', scroll: true }
                    ]
                });
                layout2.render();
            });
            layout.render();
            InitLeftData();
        });
    })();


    //加载左侧树型菜单
    var tree1=null;
    function InitLeftData(){
		    tree1 = new YAHOO.widget.TreeView("treeDiv1");
		    tree1.subscribe('clickEvent',tree1.onEventToggleHighlight);	 
		    tree1.render();
            //加载时扩展一级菜单
      		 tree1.subscribe('enterKeyPressed',function(node) {
                debugger
                alert(node.label);
			    //YAHOO.util.Dom.get('msg').innerHTML = 'Enter key pressed on node: ' + node.label;
		    });
            tree1._nodes[1].expand();

		

//		    tree1.subscribe('clickEvent',function(oArgs) {
//			    //YAHOO.util.Dom.get('msg').innerHTML = 'Click on node: ' + oArgs.node.label;
//		    });
//		    tree1.subscribe('dblClickEvent',function(oArgs) {
//			    //YAHOO.util.Dom.get('msg').innerHTML = 'Double click on node: ' + oArgs.node.label;
//		    });
        }
   
   //设置扩展与收缩
    $("#btnexpend").toggle(function(){
      $("#btnexpend").html("折叠");
        tree1._nodes[1].expandAll();
    },function(){
     $("#btnexpend").html("展开");
    tree1._nodes[1].collapseAll();
    });

    //根据部门类型来显示相应的行
    function ControlRow(id,show){
        document.getElementById(id).style.display=show;
    }
   
    //根据部门类型控制按钮的显示与隐藏
   function hidButtons(tempdeptType)
   {
        $("#divButtons").show();
        $("#divButtons").show();
        $("#divMessage").hide();
         var btnCreateCompany=$("#btnCreateCompany");
         var btnCreateSubCompany=$("#btnCreateSubCompany");
         var btnCreateDepartment=$("#btnCreateDepartment");
         var btnCreateSubDepartment=$("#btnCreateSubDepartment");
         switch(tempdeptType)
          {
             //集团下只可以新建公司
             case "0":btnCreateCompany.show();
                      btnCreateSubCompany.hide();
                      btnCreateDepartment.hide();
                      btnCreateSubDepartment.hide();
                      ControlRow("trIncorporator","block");
                      $("deptName").val("集团");
             break;
             //公司下只可以新建子公司与部门
             case "1":
                      btnCreateSubCompany.hide();
                      btnCreateDepartment.show();
                      btnCreateCompany.hide();
                      btnCreateSubDepartment.hide();
                      ControlRow("trIncorporator","block");
                      $("deptName").val("公司");
             break;
             //部门下只可以新建子部门
             case "2":
                    btnCreateSubDepartment.show();
                    btnCreateCompany.hide();
                    btnCreateDepartment.hide();
                    btnCreateSubCompany.hide();
                     ControlRow("trIncorporator","none");
                    $("deptName").val("部门");
             break;
          }

   }

       var handleSuccess2=function(o){

             $("#CompanyTable").JSONToForm(o.responseText);
             
        }
        var handleFailure2 = function (o) {
            alert(o.responseText);
        }
         var callback2 =
        {
            success: handleSuccess2,
            failure: handleFailure2,
            argument: { foo: "foo", bar: "bar" }
        };

     var currentNode=null;
     //选中树节点处理函数
     function Native(caption,key,tempdeptType){
      hidButtons(tempdeptType);
      fkey=key;
      var deptTypeName="";
      switch(tempdeptType)
      {
         case "0":deptTypeName="集团";
         break;
         case "1":deptTypeName="公司";
         break;
         case "2":deptTypeName="部门";
         break;
      }
      deptType=tempdeptType;
  
      document.getElementById("lblTitle").innerText=deptTypeName;
      document.getElementById("lbldeptName").innerText=deptTypeName;
      var url = "DataProcessin.aspx?r=" + Math.random() + "&id="+fkey+"";
      var request = YAHOO.util.Connect.asyncRequest('Post', url, callback2);
      //window.location.href='Extend/YUIList.aspx?entity=SysRole';
      setTreeNodeState(fkey); 
      currentNode.refresh();  
          if(currentNode.expanded){
             currentNode.collapse();  
          }
          else{
          currentNode.expand();   
          }
      }
      //标记树节点状态
      function setTreeNodeState(id)
      {
             //标识选中节点
         var childNodes = tree1.getNodeCount();
         var topNodes = tree1.getNodesByProperty("href");
         for (var i = 0; i < childNodes; ++i) {
                 //var id = .href.split("#@")[1];
                   if (topNodes[i].html.indexOf(id) > -1) {
                            //for (var node in topNodes) {
                            //topNodes[i].highlightState = 1; // setNodesByProperty('highlightState');
                            currentNode=topNodes[i];
                             currentNode.labelStyle = "icon-doc"; 
                            break;
                     }
            }
      }

     //添加节点
     function addNode(sLabel,id) {  
        //debugger
        if(!isEdit){
            setTreeNodeState(fkey);
            var oChildNode = new YAHOO.widget.HTMLNode(sLabel, currentNode, false);   
            currentNode.refresh();   
            currentNode.expand();   
         }
         else{
             var _c =currentNode;
         }
     } 
    //删除节点
    function deleteNode() {
            setTreeNodeState(fkey);
            tree1.removeNode(currentNode);
            tree1.draw();
    }  


   //新创建的部门或公司ID
  var newDeptID,deptName,newdeptType;
  //YAHOO.util.Event.addListener(window, "load", BindData);
   YAHOO.namespace("example.container");
 
   YAHOO.util.Event.onDOMReady(function () {
	var handleSubmit = function() {
        var editwindow = document.getElementById("EditUIWindow");
        if(editwindow)
        {
          if(editwindow.contentWindow.Save())
          {
              //添加一个节点到组织架构树上
              alert("设置成功");
               this.cancel();
          }
        }
         
       
           
	}; 
	var handleCancel = function() {
        this.cancel();
	};
	var handleSuccess = function(o) {
        var editwindow = document.getElementById("EditUIWindow");
        if(editwindow)
        {
          if(editwindow.contentWindow.Save())
          {
            alert("设置成功");
            var modeText="<a href='#"+newDeptID+"' style='display:block;cursor:hand' onclick=\"Native('"+deptName+"','"+newDeptID+"','"+newdeptType+"')\">"+deptName+"</a>";
            //添加一个节点到组织架构树上
            addNode(modeText);
            this.cancel();
          }
        }
      
	};

	var handleFailure = function(o) {
		alert("Submission failed: " + o.status);
	};

    var handleCancel1= function() {
	        };
    var callback =
        {
            success: handleSuccess1,
            failure: handleFailure1,
            argument: { foo: "foo", bar: "bar" }
        };
        //复制部门
    var handleSubmit1 = function() {
      var editwindow1= document.getElementById("EditUIWindow1");
        if(editwindow1)
        {
           editwindow1.contentWindow.Save(fkey);
        }
            alert("设置成功");
            this.cancel();
            setTreeNodeState(fkey);
            tree1.draw();
	};
    var handleSuccess1 = function(o) {
	   alert("设置成功");
      this.cancel();
	};
	var handleFailure1 = function(o) {
        alert("操作失败");
	};
    // Remove progressively enhanced content class, just before creating the module
    //YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");
	// Instantiate the Dialog
	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
							{ width : "600px",
                              height:"450px",
							  fixedcenter : true,
							  visible : false, 
                              draggable: true,
                              close: true,
                              autofillheight: "body",
							  constraintoviewport : true,
							  buttons : [ { text:"保存", handler:handleSuccess, isDefault:true },
								      { text:"取消", handler:handleCancel } ]
							});
    YAHOO.util.Dom.removeClass("dialog2", "yui-pe-content");
    YAHOO.example.container.dialog2= new YAHOO.widget.Dialog("dialog2", 
							{ width : "800px",
                              height:"360px",
							  fixedcenter : true,
                               draggable: true,
							  visible : false, 
                              autofillheight: "body",
							  constraintoviewport : true,
							  buttons : [ { text:"保存", handler:handleSuccess1, isDefault:true },
								      { text:"取消", handler:handleSuccess1 } ]
							});
	// Validate the entries in the form to require that both first and last name are entered
	YAHOO.example.container.dialog1.validate = function() {
		var data = this.getData();
		if (data.firstname == "" || data.lastname == "") {
			alert("Please enter your first and last names.");
			return false;
		} else {
			return true;
		}
	};


	YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
       //拖动大小
    var resize = new YAHOO.util.Resize("dialog1", {
        handles: ["br"],
        autoRatio: false,
        minWidth: 800,
        minHeight: 400,
        status: false
    });

	
	//YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
});
    </script>
    <script src="../../Scripts/yui.list.YUITreeList.button.event.js" type="text/javascript"></script>
</asp:Content>
